// INSE6260-ATM Simulator Project

/**
 * Model package contains core code of ATMS
 */
package com.inse6260.atms.model;

import java.util.Hashtable;

/**
 * An instance of this class implements the withdrawal fuctionality of the ATMS.
 * @author dimitri.tiago
 */
public class Withdrawal implements Transaction
{
    private int accountNumber;
    private float withdrawAmount;

    private BankDatabase bankDatabase;

    /**
     * Instantiates Withdrawal object with accountNumber and amount
     * @param accountNumber BankClient account number
     * @param withdrawalAmount withdrawal amount
     */
    public Withdrawal(BankDatabase bankDatabase, int accountNumber, float withdrawAmount)
    {
        // initialize fields
        this.accountNumber = accountNumber;
        this.withdrawAmount = withdrawAmount;
        this.bankDatabase = bankDatabase;
    }

    /**
     * Executes transaction
     */
    public void execute()
    {
        bankDatabase.insertTransLineItem(accountNumber, "debit", withdrawAmount);
        bankDatabase.debit(accountNumber, withdrawAmount);
    }
}
